package com.yunwaikeji.gy_tool_library.base;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.yunwaikeji.gy_tool_library.os.GYEnvironment;

import java.io.File;

/**
 * 基础工具类
 */
public class GYBaseUtils {
    private static Context context;//
    private static String authority;//
    private static File downloadDirectory;//下载路径
    private static File logDirectory;//日志路径
    private static File cacheDirectory;//缓存路径
    private static File videoDirectory;//视频路径
    private static File pictureDirectory;//图片路径

    public static Context getContext() {
        return context;
    }

    public static String getAuthority() {
        return authority;
    }

    public static File getDownloadDirectory() {
        return downloadDirectory;
    }

    public static File getLogDirectory() {
        return logDirectory;
    }

    public static File getCacheDirectory() {
        return cacheDirectory;
    }

    public static File getVideoDirectory() {
        return videoDirectory;
    }

    public static File getPictureDirectory() {
        return pictureDirectory;
    }

    /**
     * 初始化所有工具类
     *
     * @param context
     * @param authority
     * @return
     */
    public static InitUtils initUtils(Context context, String authority) {
        GYBaseUtils.context = context;
        GYBaseUtils.authority = authority;
        return new InitUtils()
                .setDownloadDirectory(context.getExternalFilesDir(GYEnvironment.DIRECTORY_DOWNLOAD))
                .setLogDirectory(context.getExternalFilesDir(GYEnvironment.DIRECTORY_LOG))
                .setCacheDirectory(context.getExternalCacheDir())
                .setVideoDirectory(context.getExternalFilesDir(GYEnvironment.DIRECTORY_VIDEO))
                .setPictureDirectory(context.getExternalFilesDir(GYEnvironment.DIRECTORY_PICTURE));
    }

    public static class InitUtils {
        public InitUtils setDownloadDirectory(File downloadDirectory) {
            GYBaseUtils.downloadDirectory = downloadDirectory;
            return this;
        }

        public InitUtils setLogDirectory(File logDirectory) {
            GYBaseUtils.logDirectory = logDirectory;
            return this;
        }

        public InitUtils setCacheDirectory(File cacheDirectory) {
            GYBaseUtils.cacheDirectory = cacheDirectory;
            return this;
        }

        public InitUtils setVideoDirectory(File videoDirectory) {
            GYBaseUtils.videoDirectory = videoDirectory;
            return this;
        }

        public InitUtils setPictureDirectory(File pictureDirectory) {
            GYBaseUtils.pictureDirectory = pictureDirectory;
            return this;
        }
    }

    public static Handler handler = new Handler(Looper.getMainLooper());

    public static void runOnUiThread(Runnable run) {
        handler.post(run);
    }
}
